﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RelationExpertSystem.Relation
{
    public class Step_Sibling : RelationBase
    {
        private static Step_Sibling _singleton = new Step_Sibling();
        public static Step_Sibling Instance
        {
            get { return _singleton; }
        }

        private Step_Sibling() { }

        //public override bool IsRelated(Person a, Person b)
        //{
        //    // b is a's Step_Sibling IFF b is the child of a's non-parental spouse
        //    if (!Person.IsNull(a.Mother) && !Person.IsNull(a.Mother.Spouse) && a.Mother.Spouse != a.Father)
        //    {
        //        if (!Person.IsNull(a.Father) && a.Father.KnownRelation(Child.Instance, b))
        //            return true;
        //    }
        //    if (!Person.IsNull(a.Father) && !Person.IsNull(a.Father.Spouse) && a.Father.Spouse != a.Mother)
        //    {
        //        if (!Person.IsNull(a.Mother) && a.Mother.KnownRelation(Child.Instance, b))
        //            return true;
        //    }

        //    return false;
        //}
        
        public override bool IsRelated(Person a, Person b)
        {
            // b is a's Step_Sibling IFF one of b's parents is a's step-parent
            return !Person.IsNull(b.Mother) && a.KnownRelation(Step_Parent.Instance, b.Mother) ||
                !Person.IsNull(b.Father) && a.KnownRelation(Step_Parent.Instance, b.Father);
            // checking for null here shouldn't be necessary because KnownRelation returns false on null
        }

        public override IEnumerable<IRelation> GetDependencies()
        {
            //return new HashSet<IRelation>(new IRelation[] { Spouse.Instance, Child.Instance });
            return new HashSet<IRelation>(new IRelation[] { Step_Parent.Instance, Mother.Instance, Father.Instance });
        }
    }
}
